package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.ProductCatalog;
import com.ruoyi.business.service.IProductCatalogService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 物料产品分类目录Controller
 *
 * @author honor
 * @date 2025-05-09
 */
@RestController
@RequestMapping("/business/productCatalog")
public class ProductCatalogController extends BaseController
{
    @Autowired
    private IProductCatalogService ProductCatalogService;

    /**
     * 查询物料产品分类目录列表
     */
    @PreAuthorize("@ss.hasPermi('business:productCatalog:list')")
    @GetMapping("/list")
    public AjaxResult list(ProductCatalog ProductCatalog)
    {
        List<ProductCatalog> list = ProductCatalogService.selectProductCatalogList(ProductCatalog);
        return success(list);
    }

    /**
     * 导出物料产品分类目录列表
     */
    @PreAuthorize("@ss.hasPermi('business:productCatalog:export')")
    @Log(title = "物料产品分类目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductCatalog ProductCatalog)
    {
        List<ProductCatalog> list = ProductCatalogService.selectProductCatalogList(ProductCatalog);
        ExcelUtil<ProductCatalog> util = new ExcelUtil<ProductCatalog>(ProductCatalog.class);
        util.exportExcel(response, list, "物料产品分类目录数据");
    }

    /**
     * 获取物料产品分类目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:productCatalog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ProductCatalogService.selectProductCatalogById(id));
    }

    /**
     * 新增物料产品分类目录
     */
    @PreAuthorize("@ss.hasPermi('business:productCatalog:add')")
    @Log(title = "物料产品分类目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductCatalog ProductCatalog)
    {
        return toAjax(ProductCatalogService.insertProductCatalog(ProductCatalog));
    }

    /**
     * 修改物料产品分类目录
     */
    @PreAuthorize("@ss.hasPermi('business:productCatalog:edit')")
    @Log(title = "物料产品分类目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductCatalog ProductCatalog)
    {
        return toAjax(ProductCatalogService.updateProductCatalog(ProductCatalog));
    }

    /**
     * 删除物料产品分类目录
     */
    @PreAuthorize("@ss.hasPermi('business:productCatalog:remove')")
    @Log(title = "物料产品分类目录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ProductCatalogService.deleteProductCatalogByIds(ids));
    }
}
